<html>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('gdata', '1.x');
//google.setOnLoadCallback(initialize);

function logout() {
 google.accounts.user.logout();
}

function initialize() {
  var scope = 'http://docs.google.com/feeds/';
  if (google.accounts.user.checkLogin(scope)) {   
    var service = new google.gdata.client.GoogleService('writely', 'DocList-App-v1.0');
    alert('initialize in if block'+service);	
    service.getFeed(scope + 'documents/private/full/', handleFeed, handleError);
  } else {
    var token = google.accounts.user.login(scope); // can ignore returned token
	alert('initialize in else block token:'+token);
  }
}

function handleFeed(response) {
 alert('handleFeed start of response handler');
  var entries = response.feed.entry;
  if (!entries.length) {
    alert('You have no entries!');
    return;
  }
  var html = [];
  for (var i = 0, entry; entry = entries[i]; i++) {
    var title = entry.title.$t;
    html.push('<li>' + title + '</li>');
  }
  document.getElementById('data').innerHTML = html.join('');
}

function handleError(e) {
  alert('Error: ' + e.cause ? e.cause.statusText : e.message);
}
</script>

<div id="data"><!-- dynamically filled --></div>

<div id="login">
 <input type="textbox" value="login" onclick="initialize();">
</div>
<br>
</br>
<div id="logout">
 <input type="textbox" value="logout" onclick="logout();">
</div>
</html>